define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'kzvote/complaint/index' + location.search,
                    add_url: 'kzvote/complaint/add',
                    edit_url: 'kzvote/complaint/edit',
                    del_url: 'kzvote/complaint/del',
                    multi_url: 'kzvote/complaint/multi',
                    import_url: 'kzvote/complaint/import',
                    table: 'kzvote_complaint',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,//隐藏导出
                showToggle: false,//隐藏浏览模式
                showColumns: false,//隐藏显示隐藏模式
                searchFormVisible: false,//默认显示搜索表单
                search: false,//默认显示搜索表单
                columns: [
                    [
                        {field: 'id', title: __('Id'),visible:false, operate: false},
                        {field: 'user_id', title: __('User_id'),visible:false, operate: false},
                        {field: 'user.avatar', title: __('用户头像'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.nickname', title: __('用户昵称'),visible:false, operate: false},
                        {field: 'type', title: __('Type'), operate: 'LIKE'},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'content', title: __('Content'), operate: false, formatter: Controller.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: {"10":__('Status 10'),"20":__('Status 20')}, formatter: Table.api.formatter.toggle,yes:'20',no:'10'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                content: function (value) {
                    if (value && value.length > 20) {
                        return  value.slice(0, 10) + '...<a onclick="content(this)" data-value="'+value+'">查看</a>'
                    }
                    return value
                },
            }
        }
    };
    return Controller;
});

function content(e) {
    layer.alert($(e).data('value'), {
        skin: 'layui-layer-molv' //样式类名
        ,closeBtn: 0
    }, function(){
        layer.closeAll()
    });
}